//
//  MineRootViewController.swift
//  fruit-helper-swift
//
//  Created by 赵隆杰 on 2022/6/11.
//

import UIKit

class MineRootViewController: BaseViewController {
    
    private let setImages = ["tixing", "yijianfankui", "toscore", "guanyu"]
    private let setTitles = ["阅读提醒", "意见反馈", "去评分", "关于我"]

    override func viewDidLoad() {
        super.viewDidLoad()

        navigationItem.title = "设置"
        
        tableView.estimatedRowHeight = 50
        
        tableView.frame = view.frame
        view.addSubview(tableView)
        
        tableView.register(SetTableViewCell.self, forCellReuseIdentifier: NSStringFromClass(SetTableViewCell.self))
    }
    
    

}

extension MineRootViewController {
    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 4
    }
    
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell: SetTableViewCell = tableView.dequeueReusableCell(withIdentifier: NSStringFromClass(SetTableViewCell.self), for: indexPath) as! SetTableViewCell
        cell.cellImage.image = UIImage.init(named: setImages[indexPath.row])
        cell.cellTitle.text = setTitles[indexPath.row]
        return cell
    }
    
    override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 50
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        tableView.deselectRow(at: indexPath, animated: true)
        
        if indexPath.row == 0 {
            let tixingVc = TixingViewController()
            navigationController?.present(tixingVc, animated: true, completion: {
                
            })
        } else if indexPath.row == 1 {
            let vc = YijianfankuiViewController()
            navigationController?.pushViewController(vc, animated: true)
        } else if indexPath.row == 2 {
            let url = URL(string: "itms-apps://apps.apple.com/cn/app/id1622780436?mt=8")!
            UIApplication.shared.open(url, options: [:], completionHandler: nil)
        } else if indexPath.row == 3 {
            let vc = AboutViewController()
            navigationController?.pushViewController(vc, animated: true)
        }
     }
    
}
